from threading import Thread
import threading,time
from multiprocessing import Lock

# 总票数
ticket = 50
lock_obj = Lock()
# 卖票
def sale_ticket ():
    global ticket
    for i in range(50) :
        lock_obj.acquire() #上锁
        if ticket > 0 :
            print(f'now thread is {threading.current_thread().name}, 正在售卖第{ticket}张票')
            ticket -= 1
        time.sleep(1)
        lock_obj.release()#解锁
if __name__ == '__main__':
    lst = [Thread(target=sale_ticket) for i in range(3)]
    for t in lst:
        t.start()



